package com.bc.bcapi.service;

import com.bc.bcmodel.req.OrderKycReq;
import com.bc.commonentity.common.JsonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.math.BigInteger;

import com.bc.bcapi.dao.T_Order_kycMapper;
import com.bc.bcmodel.domain.T_Order_kycModel;

/**
 * @Name T_Order_kycService * @Description TODO * @Author generation * @Date 2018/8/9 15:56:31 * @Version 1.0
 **/
@Service
public class T_Order_kycService {
    @Resource
    T_Order_kycMapper t_Order_kycMapper;

    /**
     * 保存单条数据     *      * @return
     */

    public int insert(T_Order_kycModel req) {
        return t_Order_kycMapper.insert(req);
    }

    /**
     * 批量增加数据     *      * @return
     */

    public int insertBatch(List<T_Order_kycModel> req) {
        return t_Order_kycMapper.insertBatch(req);
    }

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */

    public T_Order_kycModel findByNamedParam(T_Order_kycModel req) {
        return t_Order_kycMapper.findByNamedParam(req);
    }

    /**
     * 根据对象查询所有数据     *      * @return
     */

    public List<T_Order_kycModel> getAllList(T_Order_kycModel req) {
        return t_Order_kycMapper.findByNamedParamList(req);
    }

    /**
     * 根据对象查询所有分页数据     *      * @return
     */

    public PageInfo<T_Order_kycModel> getList(T_Order_kycModel req) {
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        List<T_Order_kycModel> list = t_Order_kycMapper.findByNamedParamList(req);
        return new PageInfo<T_Order_kycModel>(list);
    }

    /**
     * 更新指定对象     *      * @return
     */

    public int update(T_Order_kycModel req) {
        return t_Order_kycMapper.update(req);
    }

    /**
     * 删除指定数据     *      * @return
     */

    public int delete(BigInteger id) {
        return t_Order_kycMapper.delete(id);
    }

    /**
     * 根据条件统计数据量     *      * @return
     */

    public long count(T_Order_kycModel req) {
        return t_Order_kycMapper.count(req);
    }

    /**
     * 获取订单用户KYC信息
     */
    public JsonResult getOrderKycBySeller_UserId(OrderKycReq req) {
        JsonResult js = new JsonResult();
        T_Order_kycModel t_order_kycModel = new T_Order_kycModel();
        t_order_kycModel.setBuyer_user_id(req.getBuyer_user_id());
        t_order_kycModel.setSeller_user_id(req.getSeller_user_id());
        List<T_Order_kycModel> list = t_Order_kycMapper.findByNamedParamList(t_order_kycModel);
        if (list == null || list.size() <= 0) {
            js.setData(new T_Order_kycModel());
            return js;
        }
        T_Order_kycModel result = list.get(0);
        result.setImg_passport_hold(result.getImg_passport_hold());
        result.setImg_passport_after(result.getImg_passport_after());
        result.setImg_passport_front(result.getImg_passport_front());
        result.setImg_address(result.getImg_address());
        js.setData(result);
        return js;
    }
}